using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using VisualizationPackage;

namespace VisualUI
{
    public partial class frmColorMap : Form
    {
        private int _colorsCount;

        public int ColorsCount
        {
            get { return _colorsCount; }
            set { _colorsCount = value; }
        }
        private ColorMap _colorMap;

        public ColorMap ColorMap
        {
            get { return _colorMap; }
            set { _colorMap = value; }
        }

        public frmColorMap()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (rdAutoGenerate.Checked)
            {
                int count;
                if (int.TryParse(txtColorsCount.Text, out count))
                {
                    ColorsCount = count;
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                    MessageBox.Show("Please specify a valid integer");
            }
            else
            {
                if (ColorMap == null)
                    MessageBox.Show("Please specify a valid ColorMap File");
                else
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }

        private void frmColorMap_Load(object sender, EventArgs e)
        {
            lblColors.Text = ColorsCount + " color(s).";
            txtColorsCount.Text = ColorsCount.ToString();
        }

        private void lnkCancel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            DialogResult dlgRes = openFileDialog1.ShowDialog();
            if (dlgRes == DialogResult.OK)
            {
                try
                {
                    _colorMap = ColorMap.Load(openFileDialog1.FileName);
                    txtPath.Text = openFileDialog1.FileName;
                }
                catch
                {
                    MessageBox.Show("Wrong file Format");
                    _colorMap = null;
                }
            }
        }
    }
}